// pages/dingdan/dingdan.js
const {dingdanlist,tixianopenId} =require('../../util/api')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    all:"",
    shipped:"",
    toinstall:"",
    install:"",
    shownone:false,    
    dataType:'0',
    userId: "",   
    order:[] ,
    list:[
     
    ],
    daijiesuan:"",
    yijiesuan:"",
    inputValue:"",
  },

  bindHeaderTap: function (e) {   
    this.setData({
      dataType:e.currentTarget.dataset.type
    })  
    let p={
      userId:this.data.userId,
      payStatus:this.data.dataType
    }
    dingdanlist(p).then(res=>{
      for(let i=0;i< res.data.data.length;i++){
        let arr1=[];
        arr1= res.data.data[i].aaEquipmentType.etImgs.split(",")
        res.data.data[i].aaEquipmentType.arr1=arr1;
       
      }
      this.setData({
        list:res.data.data
      })
      console.log(res)

    })

  },
  bindHeaderTap1: function (e) {   
    this.setData({
      dataType:e.currentTarget.dataset.type
    })  
    let p={
      userId:this.data.userId,  
    }
    dingdanlist(p).then(res=>{
      for(let i=0;i< res.data.data.length;i++){
        let arr1=[];
        arr1= res.data.data[i].aaEquipmentType.etImgs.split(",")
        res.data.data[i].aaEquipmentType.arr1=arr1;
       
      }
      this.setData({
        list:res.data.data
      })
      console.log(res)
    })
  },

  getInputValue(e) {
    // console.log("获取value值",e.detail)   // {value: "ff", cursor: 2}
    this.setData({
      inputValue: e.detail.value
    })
    this.setData({
      searchresult: true,
    })
  },


  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
     this.setData({
      userId:wx.getStorageSync('userId')
     })
     let p={
       userId:this.data.userId,
     }
     console.log(p)
    dingdanlist(p).then(res=>{
      console.log(res)
      for(let i=0;i< res.data.data.length;i++){
        let arr1=[];
        arr1= res.data.data[i].aaEquipmentType.etImgs.split(",")
        res.data.data[i].aaEquipmentType.arr1=arr1;
       
      }
      this.setData({
        list:res.data.data,
        daijiesuan:res.data.daijiesuan,
        yijiesuan:res.data.yijiesuan,
        all:res.data.data.length,
       
      })
      console.log(this.data.list)
    })
    let pa={
      userId:this.data.userId,
      payStatus:1
    }
    dingdanlist(pa).then(res=>{
      for(let i=0;i< res.data.data.length;i++){
        let arr1=[];
        arr1= res.data.data[i].aaEquipmentType.etImgs.split(",")
        res.data.data[i].aaEquipmentType.arr1=arr1;
      }
      this.setData({
        shipped:res.data.data.length
      })
    })
    let par={
      userId:this.data.userId,
      payStatus:2
    }
    dingdanlist(par).then(res=>{
      for(let i=0;i< res.data.data.length;i++){
        let arr1=[];
        arr1= res.data.data[i].aaEquipmentType.etImgs.split(",")
        res.data.data[i].aaEquipmentType.arr1=arr1;
      }
      this.setData({
        toinstall:res.data.data.length
      })
    })
    let parm={
      userId:this.data.userId,
      payStatus:3
    }
    dingdanlist(parm).then(res=>{
      for(let i=0;i< res.data.data.length;i++){
        let arr1=[];
        arr1= res.data.data[i].aaEquipmentType.etImgs.split(",")
        res.data.data[i].aaEquipmentType.arr1=arr1;
      }
      this.setData({
        install:res.data.data.length,
      })
    })
    wx.login({
      success (res) {
        if (res.code) {
          //发起网络请求
          let a={
            username:wx.getStorageSync('username'),
           code:res.code
          }
          tixianopenId(a).then(res=>{
            console.log(res)
          })
         wx.setStorageSync('code', res.code)
        } else {
          console.log('登录失败！' + res.errMsg)
        }
      }
    })
   
 
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})